import { DataTypes } from "sequelize"

import seq from '../db/seq.js'

const User = seq.define('sys_user', {
  id: {
    type: DataTypes.UUID,
    defaultValue: DataTypes.UUIDV4, // 或 DataTypes.UUIDV1
    primaryKey: true,
    allowNull: false,
    unique: true,
    comment: '用户ID',
  },
  user_name: {
    type: DataTypes.STRING(32),
    allowNull: false,
    unique: true,
    comment: '用户名',
  },
  password: {
    type: DataTypes.STRING(64),
    allowNull: false,
    unique: true,
    comment: '密码',
  },
  email: {
    type: DataTypes.STRING(50),
    unique: true,
    comment: '邮箱',
  },
  nickname: {
    type: DataTypes.STRING(32),
    comment: '昵称',
  },
  status: {
    type: DataTypes.CHAR(1),
    allowNull: false,
    defaultValue: '0',
    comment: '账号状态（0正常 1停用）',
  },
  user_type: {
    type: DataTypes.CHAR(1),
    allowNull: false,
    defaultValue: '1',
    comment: '用户类型（0 测试用户 1 普通用户）',
  },
  remark: {
    type: DataTypes.STRING,
    comment: '备注',
  },
}, {
  // 防止表名变成复数
  freezeTableName: true
})

// User.sync({ force: true })

export default User